local mengli = fk.CreateSkill {

  name = "joy__mengli",

  tags = { Skill.Compulsory, },

}



mengli:addEffect(fk.HpChanged, {
  name = "joy__mengli",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill(mengli.name) and (((player.general == "joyo__baili" or player.deputyGeneral == "joyo__baili") and player.hp > 3) or ((player.general == "joyo__heili" or player.deputyGeneral == "joyo__heili") and player.hp <= 3))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.general == "joyo__baili" and player.hp > 3 then
      player.general = "joyo__heili"
      player.room:broadcastProperty(player, "general")
    elseif player.general == "joyo__heili" and player.hp <= 3 then
      player.general = "joyo__baili"
      player.room:broadcastProperty(player, "general")
    end
    if player.deputyGeneral == "joyo__baili" and player.hp > 3 then
      player.deputyGeneral = "joyo__heili"
      player.room:broadcastProperty(player, "deputyGeneral")
    elseif player.deputyGeneral == "joyo__heili" and player.hp <= 3 then
      player.deputyGeneral = "joyo__baili"
      player.room:broadcastProperty(player, "deputyGeneral")
    end
    if not player.dead then
      player:drawCards(1,mengli.name)
    end
    room.logic:trigger("fk.joy__tunxing", player)
  end,
})

return mengli